* Multiproduct Firms, Horizontal Mergers, and International Trade
* Jackie M.L. Chan, Michael Irlacher, and Michael Koch

* This do file runs additional regressions for domestic market outcomes with the synthetic merger control group.

foreach v in 3c 4c 9c{
	
if "`v'"=="3c"{
	local table "A11"	
	}
if "`v'"=="4c"{
	local table "figureA6"	
	}	
if "`v'"=="9c"{
	local table "figureA7"	
	}	
	
* From Do File #R14a
use "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\temp_did_imputation_vars_dom_prepare_jc_synthetic_02102023_v`v'.dta", clear

* From Do File #R14b
merge 1:1 cvrnrA aar aarA using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\temp_did_imputation_vars_dom_prepare_jc_synthetic_02102023_AT_v`v'.dta", keepusing(nprodAT nprodAT_nodup lnnprodAT_nodup nprodT) keep(match master) nogen

* Merge with firm-level data
rename cvrnrA cvrnr
rename aar aar_ori
rename aarA aar
merge 1:1 cvrnr aar using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\data\temp_firm_subset1865.dta", keep(match master) nogen
rename aar aarA
rename aar_ori aar
rename cvrnr cvrnrA

* Drop if merger event occurs before 1999 (not enough years for pre-merger period)
drop if aar<1999 & acquirer==1

* Drop if acquirer has no merger event in remaining sample
egen meanaar = mean(aar), by(cvrnrA)
drop if meanaar==. & acquirer==1

* Drop if acquirer has multiple merger events
egen sdaar = sd(aar), by(cvrnrA)
drop if sdaar>0 & sdaar!=.

* Calculate minimum number of employees in sample
egen minemployee_cvrnr = min(employee_cvrnr) if nprod_dro>0 & nprod_dro!=., by(cvrnrA)

* Additional calculations
replace d_yr = aarA - meanaar

qui tab aarA, gen(D_AA_)
qui tab aar, gen(D_A_)

* Define spells for imputation estimator
gsort cvrnrA -aarA
by cvrnrA: carryforward aar, gen(aar2)
sort cvrnrA aarA
by cvrnrA: carryforward aar2, gen(aar3)
replace aar3 = aar3+1

gen p4 = (d_yr>3)
gen m4 = (d_yr<-3)

foreach x in p4 p3 p2 p1 m1 m2 m3 m4{
replace `x' = 0 if acquirer==0
}

foreach i of numlist 1(1)3{
gen M`i'=0
replace M`i'=1 if d_yr==-`i'
}

foreach i of numlist 1(1)3 {
gen P`i'=0
replace P`i'=1 if d_yr==`i'
}

gen P4 = (d_yr>3)
gen M4 = (d_yr<-3)

foreach x in P4 P3 P2 P1 M1 M2 M3 M4{
gen `x'Xa = `x'*acquirer
}

gen post = (d_yr>0)
gen postXa = post*acquirer

foreach x in lnnprod {
areg `x' P4 P3 P2 P1 test M1 M2 M3 M4 P4Xa P3Xa P2Xa P1Xa M1Xa M2Xa M3Xa M4Xa D_AA_1-D_AA_22 if minemployee_cvrnr>=10, absorb(cvrnrA) cluster(ind)
outreg2 using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\output\table_`table'.txt", keep(P4 P3 P2 P1 test M1 M2 M3 M4 P4Xa P3Xa P2Xa P1Xa M1Xa M2Xa M3Xa M4Xa D_AA_1-D_AA_22) bdec(4) sdec(4) nocons nonotes 
}

foreach x in lnnprodAT_nodup {
areg `x' P4 P3 P2 P1 test M1 M2 M3 M4 P4Xa P3Xa P2Xa P1Xa M1Xa M2Xa M3Xa M4Xa D_AA_1-D_AA_22 if minemployee_cvrnr>=10 & ((acquirer==1 & ((nprodT>0 & d_yr<=0) | d_yr>0)) | (acquirer==0 & nprodT>0)), absorb(cvrnrA) cluster(ind)
outreg2 using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\output\table_`table'.txt", keep(P4 P3 P2 P1 test M1 M2 M3 M4 P4Xa P3Xa P2Xa P1Xa M1Xa M2Xa M3Xa M4Xa D_AA_1-D_AA_22) bdec(4) sdec(4) nocons nonotes 
}

foreach x in theil_fy lnrev_max lnrev_med lnrev_min {
areg `x' P4 P3 P2 P1 test M1 M2 M3 M4 P4Xa P3Xa P2Xa P1Xa M1Xa M2Xa M3Xa M4Xa D_AA_1-D_AA_22 if minemployee_cvrnr>=10, absorb(cvrnrA) cluster(ind)
outreg2 using "D:\Data\Workdata\703989\FJSJ3989\CIK\replication_restat\output\table_`table'.txt", keep(P4 P3 P2 P1 test M1 M2 M3 M4 P4Xa P3Xa P2Xa P1Xa M1Xa M2Xa M3Xa M4Xa D_AA_1-D_AA_22) bdec(4) sdec(4) nocons nonotes 
}
}